package com.meirimoney.app;

import net.youmi.android.AdManager;
import net.youmi.android.offers.OffersManager;

import com.dlnetwork.Dianle;
import com.meirimoney.app.control.MenuBar;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class AdvertisingPanel extends BaseActivity implements OnClickListener
{
	/**
	 ********* 广告墙配置开始*********
	 * 
	 */

	/**
	 * 初始化有米广告
	 */
	private void initializeYoumi()
	{
		// 初始化应用发布ID和密钥，以及设置测试模式
		AdManager.getInstance(this).init("98c1f5a4ed1ae458",
				"c5704b440bd9d7d6", false);// false

		// 请务必调用以下代码，告诉SDK应用启动，可以让SDK进行一些初始化操作。该接口务必在SDK的初始化接口之后调用。
		OffersManager.getInstance(this).onAppLaunch();

		// 调用以下接口关闭有米广告SDK相关的log
		AdManager.getInstance(this).setEnableDebugLog(false);
		OffersManager.getInstance(this).setCustomUserId(
				this.getUser().getUserId());
	}

	/**
	 * 万普世纪广告配置
	 */
	private void initializeWaps()
	{
		/**
		cn.waps.AppConnect.getInstance("574086a8f315b366300ce189eadf78f2",
				"gfan", this); // 设置WAPS_ID和WAPS_PID
		cn.waps.AppConnect.getInstance(this).setAdViewClassName(
				"com.meirimoney.app.WapsWebView");
		
		 **/
		  cn.waps.AppConnect.getInstance(this);
	}

	/**
	 * 初始化点乐
	 */
	private void initializeDianle()
	{
		Dianle.initDianleContext(this, "b1c7cf1a3f0308a8019deca9ec97d292");
		Dianle.setCustomActivity("com.meirimoney.app.DianleWall");
		Dianle.setCustomService("com.meirimoney.app.DianleWallService");
		Dianle.setCurrentUserID(this.getUser().getUserId());
	}

	/**
	 * 加载广告
	 */
	public void loadAdvertising()
	{
		this.initializeYoumi();
		this.initializeDianle();
		this.initializeWaps();
	}

	/**
	 * 卸载广告
	 */
	public void unloadAdvertising()
	{
		/**
		 * 有米的广告卸载
		 */
		OffersManager.getInstance(this).onAppExit();

		/**
		 * 万普世纪广告卸载
		 */
		cn.waps.AppConnect.getInstance(this).close();
	}

	/**
	 ********** 广告墙配置结束**********
	 */

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.loadAdvertising();
		this.initializeUI();
		this.setTitle("任务列表");
	}
	
	/***
	 * 初始化当前界面的UI
	 */
	private void initializeUI()
	{
		this.setContentView(R.layout.mrm_advertising_list);
		if (null == this.navigation)
		{
			this.navigation = (MenuBar) this.findViewById(R.id.head);
		}
		if (null == this.youmiNavigation)
		{
			this.youmiNavigation = (TextView) this.findViewById(R.id.goYoumi);
			this.youmiNavigation.setOnClickListener(this);
		}
		if (null == this.wapsNavigation)
		{
			this.wapsNavigation = (TextView) this.findViewById(R.id.goWaps);
			this.wapsNavigation.setOnClickListener(this);
		}
		if (null == this.dianleNavigation)
		{
			this.dianleNavigation = (TextView) this.findViewById(R.id.goDianLe);
			this.dianleNavigation.setOnClickListener(this);
		}
		if (null == this.tuanNavigation)
		{
			this.tuanNavigation = (TextView) this.findViewById(R.id.goTuan);
			this.tuanNavigation.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v)
	{
		if (v.getId() == R.id.goYoumi)
		{
			OffersManager.getInstance(this).showOffersWall();
		} else if (v.getId() == R.id.goDianLe)
		{
			Dianle.showOffers();
		} else if (v.getId() == R.id.goWaps)
		{
			cn.waps.AppConnect.getInstance(this).showOffers(this,
					this.getUser().getUserId());
		} else if (v.getId() == R.id.goTuan)
		{
			cn.waps.AppConnect.getInstance(this).showTuanOffers(this,
					this.getUser().getUserId());
		}
	}

	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		this.unloadAdvertising();
	}

	/**
	 * 有米导航
	 */
	private TextView youmiNavigation;

	/**
	 * 点乐导航
	 */
	private TextView dianleNavigation;

	/**
	 * 点入导航
	 */
	private TextView wapsNavigation;

	/**
	 * 团购赚积分
	 */
	private TextView tuanNavigation;
}
